//多维数组排序
data = [{"id":"1","name":"123221"},{"id":"2","name":"你好"},{"id":"5","name":"我好"},{"id":"3","name":"大家好"},{"id":"4","name":"真的好"}];

var by = function(name){
return function(o, p){
	var a, b;
	if (typeof o === "object" && typeof p === "object" && o && p) {
		a = o[name];
		b = p[name];
		if(a === b){return 0;}
			if (typeof a === typeof b){
				return a < b ? -1 : 1;
			}
			return typeof a < typeof b ? -1 : 1;
		}
		else{
			throw ("error"); 
		}
	}
}
//排序
data = data.sort(by("id"));
console.log(data);
//删除第一个元素
//data.shift();
console.log(data);
//重新索引键值
var indexArray = function(array){
	for(var i = 0,len = array.length; i < len; i++){
		array[i].id = i;
	}

	return array;
}

indexArray(data);

//追加最后一个元素
data.push({"id":"5","name":"adfa"});
console.log(data);

//获取指定key值
var keyword = "你好";

var id = new Array();
for(var i = 0, len = data.length; i < len; i++){
	if(data[i].name == keyword){
		id[0] = i;
	}
}
console.log(id);
//删除指定元素
data.splice(id[0],1)
data = data.sort(by("id"));
indexArray(data);
console.log(data);
